package com.ssm.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.ssm.controller.BaseController;
import com.ssm.entity.DepartmentpeopleDatailedent;
import com.ssm.service.DepartmentPeopleService;
import com.ssm.service.DepartmentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class AdminMemberController extends BaseController {
    @Resource(name="departmentPeopleService")
    private DepartmentPeopleService departmentPeopleService;

    // 查询
    @RequestMapping(value ="departmentpeople/manage",method = RequestMethod.GET)
    public String DepartmentpeopleDatailedentQuery(HttpSession session, Map<String,Object> map){
        List<DepartmentpeopleDatailedent> list =new ArrayList<>();
        logger.info("检查管理员权限");
        String adminId=checkAdmin(session);
        if (!adminId.equals("adminId")){
            return "redirect:/";
        }
         list=departmentPeopleService.DepartmentpeopleDetailed();
        map.put("departmentnames",list);
        //DepartmentpeopleDatailedent de=list.get(1);
        //logger.info("--------------->"+de);
        for (int i = 0; i < list.size(); i++) {
            logger.info(list.get(i));
        }
        return "admin/departmentpeople";
    }
    //删除
    @ResponseBody
    @RequestMapping(value = "departmentpeople/delete",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public String delete(HttpSession session,  @RequestParam Integer id){
        logger.info("检查管理员权限");
        String adminId=checkAdmin(session);
        if (!adminId.equals("adminId")){
            return "redirect:/";
        }
        Integer IsSuccess=departmentPeopleService.deleteDepartmentPeople(id);
        JSONObject object=new JSONObject();
        if (IsSuccess==1){
            logger.info("删除成功");

            object.put("status","success");
        }else{
            logger.info("删除错误");
            object.put("status","false");
        }
        return object.toJSONString();
    }
}


